package com.sanno.maintain.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sanno.common.entity.SncUserLogin;
import com.sanno.maintain.dao.MenuDao;
import com.sanno.maintain.entity.Childer1;
import com.sanno.maintain.entity.Childer2;
import com.sanno.maintain.entity.SccRoleMenu;
import com.sanno.maintain.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, SccRoleMenu> implements MenuService {

    @Resource
    private MenuDao menuDao;

    @Override
    public List<Childer2> queryMenu(int menuId,int roleId,int userId) {

        List<SncUserLogin> sncUserLogin = menuDao.findUser(userId,roleId);

        List<Childer2> childer2List = menuDao.queryMenu(menuId,roleId);
        for (Childer2 childer2 : childer2List) {
            List<Childer2> list = menuDao.find(childer2.getId(),menuId);
            if (list.size() > 0){
                childer2.setChecked(true);
                if (sncUserLogin.size() > 0){
                    menuDao.updateMenu2(childer2.getId());
                }
            }else{
                if (sncUserLogin.size() > 0){
                    menuDao.updateMenu1(childer2.getId());
                }
            }
        }
        return childer2List;
    }

}
